package com.wbs.controller;

import com.wbs.aop.LogAn;
import com.wbs.vo.BrandVO;
import com.wbs.vo.SpecificationVO;
import com.wbs.resutil.PageBean;
import com.wbs.resutil.PageResult;
import com.wbs.resutil.Result;
import com.wbs.service.SpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author: 芝梦
 * @Description: 规格管理 控制层
 *REST风格介绍:  POST    增加
 *              PUT     修改
 *              DELETE  删除
 * @RequestBody         接收  json数据, 复杂数据
 * @RequestParam        接收  简单数据
 * @DateTime: 2024/1/24 11:29
 */
@RequestMapping("specification")
@RestController
public class SpecificationController {
    @Autowired
    private SpecificationService specificationService;

    /**
     * @RequestBody 注解 用于接收前端发送的json数据
     * @return
     */
    //查询所有规格信息
    @GetMapping("findSpecificationAll")
    public Result findSpecificationAll(){
        List<SpecificationVO> specificationVOList = specificationService.findSpecificationAll();
        return Result.SUCCESS().setData(specificationVOList);
    }

    //查询所有品牌信息
    @LogAn
    @PostMapping("findSpecificationPage")
    public Result findSpecificationPage(@RequestBody PageBean<SpecificationVO> pageBean){
        PageResult<SpecificationVO> pageResult = specificationService.findSpecificationPage(pageBean);
        return Result.SUCCESS().setData(pageResult);
    }

    //根据id查询规格和规格组成
    @GetMapping("selectByKey")
    public Result selectByKey(@RequestParam Long id){
        SpecificationVO specificationVO = specificationService.selectByKey(id);
        return Result.SUCCESS().setData(specificationVO);
    }

    @PostMapping("add")
    public Result add(@RequestBody SpecificationVO specificationVO){
        specificationService.add(specificationVO);
        return Result.SUCCESS();
    }
    @PutMapping("update")
    public Result update(@RequestBody SpecificationVO specificationVO){
        specificationService.update(specificationVO);
        return Result.SUCCESS();
    }

    @DeleteMapping("delete")
    public Result delete(@RequestParam Long id){
        specificationService.delete(id);
        return Result.SUCCESS();
    }

}
